package com.hzm.controller;

import com.hzm.dao.UserRepository;
import com.hzm.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {

    @Autowired
    UserRepository userRepository;

    @RequestMapping("/user/{id}")
    public User getUserById(@PathVariable("id") Integer id){
        User user = userRepository.findById(id).get();
        return user;
    }

    @RequestMapping("/insert")
    public User insertUser(User user){
        User save = userRepository.save(user);
        return save;
    }
}
